function [model] = acados_robot_model()
% 2024/03/25
% Author: LHP
% Description: diff drive robot model defined by CasADi

    import casadi.*
    model = struct();
    constraint = struct();
    model_name = 'diff_drive_robot_model';

%% CasADi Model

    nx = 5;
    nu = 2;

    % 定义符号变量
    % 定义状态向量：x方向位置/y方向位置/姿态
    %X  = SX.sym('X', nx, 1);                                % 状态向量
    %Xr = SX.sym('Xr', nx, 1);                               % 参考状态:Xr=[xr;ur]
    x = SX.sym('x');
    y = SX.sym('y');
    theta = SX.sym('theta');
    v = SX.sym('v');
    omega = SX.sym('omega');
    X = vertcat(x, y, theta, v, omega);

    xr = SX.sym('xr');
    yr = SX.sym('yr');
    thetar = SX.sym('thetar');
    vr = SX.sym('vr');
    omegar = SX.sym('omegar');
    Xr = vertcat(xr, yr, thetar, vr, omegar);

    y_ref   = zeros(nx, 1);
    y_ref_e = zeros(nx, 1);

    % 定义控制输入向量：线速度/角速度
    %u = MX.sym('u',nu,1);                                   % 输入向量:u=[dv;domega]
    a = SX.sym('a');
    b = SX.sym('b');
    u = vertcat(a, b);

    % 创建状态变量的导数
    %Xdot = MX.sym('Xdot', nx, 1); 
    xdot = SX.sym('xdot');
    ydot = SX.sym('ydot');
    thetadot = SX.sym('thetadot');
    vdot = SX.sym('vdot');
    omegadot = SX.sym('omegadot');
    Xdot = vertcat(xdot, ydot, thetadot, vdot, omegadot);

    % 定义系统模型:显式动态方程f_expl /cos(X(3))/sin(X(3) = cos(pi/2 - X(3))
    %f_expl = vertcat(X(4) * cos(X(3)), X(4) * sin(X(3)), X(5), u(1), u(2)); 
    f_expl = vertcat(v*cos(theta), v*sin(theta), omega, a, b); 

    % 代价权重矩阵
    Q = eye(nx);                                            % 状态权重矩阵初始值

    % 定义约束

%   通用代价函数形式(ext_cost中使用)
%   cost_expr_ext_cost_e = (X-Xr)'*Q*(X-Xr);               % 终端代价 (only states)
%   cost_expr_ext_cost   = (X-Xr)'*Q*(X-Xr) + u'*R*u;      % 过程代价 (states and inputs)

    % 终端不变集约束
    %x_term = (X-Xr)'*Q*(X-Xr);                             % Q不能变??
    % 终端不变集约束的函数表达式
    %constraint.xterm = Function('x_term', {X, Xr}, {x_term}); 
    % 设置约束表达式,具体的约束范围在后续的代码中会设置
    %constraint.expr = vertcat(x_term);
    % 约束范围
    %constraint.xterm_max = 0;  % 最大值

    % (状态变量中的)控制输入约束
    model.v_min     = -0.5;                                 % 线速度的最小值[m/s]
    model.v_max     = 0.5;                                  % 线速度的最大值 [m/s]
    model.omega_min = -0.5;                                 % 角速度的最小值[rad/s]
    model.omega_max = 0.5;                                  % 角速度的最大值[rad/s]

    % Define initial conditions
    % model.x0 = [0; 0; pi/2];                              % 设置初始状态条件

    % Define model struct
    model.f_expl_expr = f_expl;                             % 设置显式动态方程
    model.f_impl_expr = Xdot - f_expl;
    model.x           = X;                                  % 设置状态变量
    model.xdot        = Xdot;                               % 设置状态变量的导数
    model.u           = u;                                  % 设置控制变量
    model.p           = [];                                 % 设置参考状态变量 Xr
    model.name        = model_name;                         % 设置模型名称
    model.W           = Q;                                  % 过程状态权重矩阵,变化
    model.W_e         = Q;                                  % 终端状态权重矩阵,不变
    model.y_ref       = y_ref;                              % 过程状态参考值,变化
    model.y_ref_e     = y_ref_e;                            % 终端状态参考值,变化

% (ext_cost时使用)
% model.cost_expr_ext_cost = cost_expr_ext_cost;
% model.cost_expr_ext_cost_e = cost_expr_ext_cost_e;
end